package com.sixth.controller;

import com.sixth.service.UserService;
import com.sixth.util.CommonResult;
import com.sixth.util.TableLayUi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @program: Keyboard-5
 * @description:
 * @author: 高振杨
 * @create: 2022-01-12 13:23
 **/
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    //退出登录
    @RequestMapping("out")
    public void Out(HttpServletRequest request, HttpServletResponse response) throws Exception{
        request.getSession().invalidate();
        response.sendRedirect(request.getContextPath() + "/login.jsp");
    }

    //批量删除
    @RequestMapping("dels")
    public CommonResult dels(String user){
        return userService.batch(user);
    }

    //根据条件查询用户
    @RequestMapping("listByCondition")
    public TableLayUi listByCondition(int page, int limit,String realname,String loginname,String address,String phone,String identity ,Integer sex)  {

        //System.out.println(page+limit+realname+loginname+address+phone+identity+sex);

        return userService.listByCondition(page,limit,realname,loginname,address,phone,identity,sex);
    }

    //添加用户
    @RequestMapping("/userAdd")
    public CommonResult userAdd(String loginname,String identity, String realname, Integer sex, String address, String phone,String pwd,String position,Integer type){

        //System.out.println(realname + loginname + address+ phone+ identity+ sex+ pwd+ type+ position);

        CommonResult addUser = userService.AddUser(loginname, identity, realname, sex, address, phone, pwd, position, type);
        return addUser;
    }

    //修改
    @RequestMapping("/edit")
    public CommonResult edit(Integer userid,String loginname,String identity, String realname, Integer sex, String address, String phone,Integer type){

        System.out.println(realname + loginname + address+ phone+ identity+ sex+ type);

        CommonResult addUser = userService.editUser(userid,loginname, identity, realname, sex, address, phone, type);
        return addUser;
    }

    //修改密码
    @RequestMapping("/updatePassword")
    public CommonResult updatePassword(Integer userid,String pwd){

        System.out.println(userid+pwd);

        CommonResult addUser = userService.updatePassword(userid,pwd);
        return addUser;
    }


    //删除用户
    @RequestMapping("/deleteUser")
    public CommonResult deleteUser(Integer userid){

       // System.out.println(userid);
        CommonResult addUser = userService.deleteUser(userid);
        return addUser;
    }


}
